import fs from "fs";
import path from "path";

// 封装的递归删除目录和内部文件
const deleteFolderRecursive = function (directoryPath) {
  if (fs.existsSync(directoryPath)) {
    fs.readdirSync(directoryPath).forEach(function (file, index) {
      const curPath = path.join(directoryPath, file);
      if (fs.lstatSync(curPath).isDirectory()) {
        // 如果是文件夹，递归调用
        deleteFolderRecursive(curPath);
      } else {
        // 如果是文件，直接删除
        fs.unlinkSync(curPath);
      }
    });
    fs.rmdirSync(directoryPath); // 删除目录自身
  }
};

deleteFolderRecursive(`${process.cwd()}/src/api/swagger`);
